package com.apkcore.core.net

import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

object HttpUtils {
    private val gson by lazy { Gson() }

    fun mapToRequestBodyAny(map: Map<String, Any?>): RequestBody {
        val toJson = gson.toJson(map)
        return toJson.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
    }

    fun jsonToRequestBody(toJson: String): RequestBody {
        return toJson.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
    }
}